<template>
  <el-container class="app-container" style="height: 100%;box-sizing: border-box">
    <el-aside>
      <el-tree
        class="z-tree-border"
        :data="treeData"
        :props="treeProps"
        @node-click="handleNodeClick"
        default-expand-all
        :expand-on-click-node="false"
      >
      </el-tree>
    </el-aside>
    <el-main>
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
               label-width="68px">
        <el-form-item label="考题编码" prop="code">
          <el-input
            v-model="queryParams.code"
            placeholder="请输入考题编码"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="部门" prop="deptId">
          <el-select
            v-model="queryParams.deptId"
            placeholder="请输入部门"
            clearable
            @keyup.enter.native="handleQuery"
          >
            <el-option
              v-for="item in options.deptList"
              :value="item.deptId"
              :label="item.deptName"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="大纲" prop="syllabusCode">
          <el-select
            v-model="queryParams.syllabusCode"
            placeholder="请输入大纲"
            clearable
            @keyup.enter.native="handleQuery"
          >
            <el-option
              v-for="dict in dict.type.syllabus"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="能力级别" prop="postLevelCode">
          <el-select
            v-model="queryParams.postLevelCode"
            placeholder="请输入能力级别"
            clearable
            @keyup.enter.native="handleQuery"
          >
            <el-option
              v-for="dict in dict.type.post_level"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"

          >新增
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"

          >修改
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"

          >删除
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"

          >导出
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="info"
            plain
            icon="el-icon-upload2"
            size="mini"
            @click="handleImport"

          >导入
          </el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table border v-loading="loading" :data="ExamQuestionBankList" @selection-change="handleSelectionChange">
        <el-table-column resizable show-overflow-tooltip type="selection" width="55" align="center"/>
        <el-table-column resizable show-overflow-tooltip label="考题编码" align="center" prop="code"/>
        <el-table-column resizable show-overflow-tooltip label="部门" align="center" prop="deptId">
          <template v-slot="{row}">
            {{options.deptMap[row.deptId]}}
          </template>
        </el-table-column>
        <el-table-column resizable show-overflow-tooltip label="大纲" align="center" prop="syllabusCode">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.syllabus" :value="scope.row.syllabusCode"/>
          </template>
        </el-table-column>
        <el-table-column resizable show-overflow-tooltip label="岗位" align="center" prop="postId">
          <template slot-scope="{row}">
            {{options.postMap[row.postId]}}
          </template>
        </el-table-column>
        <el-table-column resizable show-overflow-tooltip label="科目" align="center" prop="subjectId">
          <template slot-scope="{row}">
            {{options.examSubjectKnowledgePointsMap[row.subjectId]}}
          </template>
        </el-table-column>
        <el-table-column resizable show-overflow-tooltip label="知识点" align="center" prop="knowledgePointsId">
          <template slot-scope="{row}">
            {{options.examSubjectKnowledgePointsMap[row.knowledgePointsId]}}
          </template>
        </el-table-column>
        <el-table-column resizable show-overflow-tooltip label="考题类型" align="center" prop="questionType">
          <template v-slot="{row}">
            {{options.QUESTION_TYPE.map[row.questionType]}}
          </template>
        </el-table-column>
        <el-table-column resizable show-overflow-tooltip label="题干内容" align="center" prop="content"/>
        <!--        <el-table-column resizable show-overflow-tooltip label="正确答案" align="center" prop="rightKey"/>-->
        <el-table-column resizable show-overflow-tooltip label="能力级别" align="center" prop="postLevelCode">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.post_level" :value="scope.row.postLevelCode"/>
            </template>
        </el-table-column>
        <!--        <el-table-column resizable show-overflow-tooltip label="试题解析" align="center" prop="analysis"/>-->
        <!--        <el-table-column resizable show-overflow-tooltip label="备注" align="center" prop="remark"/>-->
        <el-table-column resizable label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"

            >修改
            </el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"

            >删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

      <!-- 添加或修改题库管理对话框 -->
      <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
        <el-row>
          <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <el-col :span="12">
              <el-form-item label="考题编码" prop="code">
                <el-input v-model="form.code" placeholder="请输入考题编码" style="width: 320px"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="部门" prop="deptId">
                <el-select v-model="form.deptId" placeholder="请输入部门" style="width: 320px">
                  <el-option
                    v-for="item in options.deptList"
                    :label="item.deptName"
                    :value="item.deptId"

                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="大纲" prop="syllabusCode">
                <el-select v-model="form.syllabusCode" placeholder="请输入大纲" style="width: 320px">
                  <el-option
                    v-for="dict in dict.type.syllabus"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="知识点" prop="knowledgePointsId">
                <el-cascader @change="handleKnowledgePointsChange" v-model="form.knowledgePointsId"
                             :options="knowledgePointsTree" :props="{value: 'id', label: 'name'}" placeholder="请输入知识点"
                             style="width: 320px"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="能力级别" prop="postLevelCode">
                <el-select v-model="form.postLevelCode" placeholder="请输入能力级别" style="width: 320px">
                  <el-option
                    v-for="dict in dict.type.post_level"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="类型" prop="questionType">
                <el-select v-model="form.questionType" @change="handleQuestionTypeChange" placeholder="请输入类型" style="width: 320px">
                  <el-option
                    v-for="item in options.QUESTION_TYPE.list"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="题干内容" prop="content">
                <el-input v-model="form.content" type="textarea" :autosize="{ minRows: 2, maxRows: 12}" placeholder="请输入题干内容" style="width: 800px"
                          maxlength="500" show-word-limit/>
              </el-form-item>
            </el-col>
            <el-col :span="24" v-if="~[options.QUESTION_TYPE.enums.ChoiceQuestion.value, options.QUESTION_TYPE.enums.FillBlankQuestionExcel.value].indexOf(form.questionType)">
              <el-form-item :rules="{required: true,message: '请输入选项',trigger: 'blur'}" :label='options.QUESTION_TYPE.enums.ChoiceQuestion.value === form.questionType ? `选项${options.Choice_Question_Option.map[index]}` : `答案${index+1}`' :prop="`examQuestionBankOptionList.${index}`" v-for="(option, index) in form.examQuestionBankOptionList">
                <el-input v-model="form.examQuestionBankOptionList[index]" placeholder="请输入选项" style="width: 690px">
                </el-input>
                <el-button @click="handleAddOption(index)" type="primary" icon="el-icon-circle-plus" size="small" style="margin-left: 10px"></el-button>
                <el-button @click="handleRemoveOption(index)" type="danger" icon="el-icon-remove" size="small"></el-button>
              </el-form-item>
            </el-col>
            <el-col :span="12" v-if="~[options.QUESTION_TYPE.enums.ChoiceQuestion.value, options.QUESTION_TYPE.enums.JudgeQuestion.value].indexOf(form.questionType)">
              <el-form-item label="正确答案" prop="rightKey">
                <el-select v-model="form.rightKey" v-if="form.questionType === options.QUESTION_TYPE.enums.ChoiceQuestion.value" clearable multiple>
                  <el-option
                    v-for="(item1,index1) in options.Choice_Question_Option.list"
                    v-bind="item1"
                    :key="item1.value"
                  >
                  </el-option>
                </el-select>
                <el-select v-if="form.questionType === options.QUESTION_TYPE.enums.JudgeQuestion.value" v-model="form.rightKey" placeholder="请输入正确答案" style="width: 320px">
                  <el-option
                    v-for="item in options.JUDGE_QUESTION_RIGHT_KEY.list"
                    v-bind="item"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="试题解析" prop="analysis">
                <el-input v-model="form.analysis" type="textarea" :autosize="{ minRows: 2, maxRows: 12 }" placeholder="请输入内容" maxlength="500" show-word-limit
                          style="width: 800px"/>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="备注" prop="remark">
                <el-input v-model="form.remark" type="textarea" :autosize="{ minRows: 2, maxRows: 12}" placeholder="请输入内容" maxlength="500" show-word-limit
                          style="width: 800px"/>
              </el-form-item>
            </el-col>
          </el-form>
        </el-row>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>

      <!-- 导入对话框 -->
      <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
        <el-upload
          ref="upload"
          :limit="1"
          accept=".xlsx, .xls"
          :action="upload.url"
          :disabled="upload.isUploading"
          :headers="upload.headers"
          :on-progress="handleFileUploadProgress"
          :on-success="handleFileSuccess"
          :auto-upload="false"
          :on-error="handleFileError"
          drag
        >
          <i class="el-icon-upload"></i>
          <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
          <div class="el-upload__tip text-center" slot="tip">
            <span>仅允许导入xls、xlsx格式文件。</span>
<!--            <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>-->
          </div>
        </el-upload>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitFileForm">确 定</el-button>
          <el-button @click="upload.open = false">取 消</el-button>
        </div>
      </el-dialog>
    </el-main>
  </el-container>
</template>

<script src="./index.js"/>
